package com.demo2do.fms.admin.service.supplier.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.fms.admin.dao.supplier.SupplierProfileDao;
import com.demo2do.fms.admin.service.DataServiceImpl;
import com.demo2do.fms.admin.service.supplier.SupplierStaffService;
import com.demo2do.fms.entity.supplier.common.KeyPost;
import com.demo2do.fms.entity.supplier.common.Supplier;
import com.demo2do.fms.entity.supplier.common.SupplierStaff;

/**
 * 
 * @author Wy
 *
 */
@Service("supplierStaffService")
public class SupplierStaffServiceImpl extends DataServiceImpl<SupplierStaff> implements SupplierStaffService{

    @Dao
    private SupplierProfileDao supplierStaffDao;

    /*
     * (non-Javadoc)
     * @see com.demo2do.fms.admin.service.supplier.SupplierStaffService#listSupplierStaff(java.lang.Long)
     */
    public List<SupplierStaff> listSupplierStaff(Long supplierId) {
        return supplierStaffDao.listSupplierStaff(supplierId);
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.fms.admin.service.supplier.SupplierStaffService#getSupplierStaff(java.lang.Long, java.lang.String)
     */
    public SupplierStaff getSupplierStaff(Long supplierId, String keyPost) {
        return supplierStaffDao.getSupplierStaff(supplierId, KeyPost.codeOf(keyPost));
    }

    /* (non-Javadoc)
     * @see com.demo2do.fms.admin.service.supplier.SupplierStaffService#create(com.demo2do.fms.entity.supplier.common.SupplierStaff, com.demo2do.fms.entity.supplier.common.Supplier, java.lang.Long)
     */
    public void create(SupplierStaff supplierStaff, Supplier supplier, Long operator) {
        genericDaoSupport.save(supplierStaff.initialzie(supplier, operator));
    }

    /* (non-Javadoc)
     * @see com.demo2do.fms.admin.service.supplier.SupplierStaffService#edit(com.demo2do.fms.entity.supplier.common.SupplierStaff, java.lang.Long)
     */
    public void edit(SupplierStaff SupplierStaff, Long operator) {
        genericDaoSupport.update(SupplierStaff.edit(operator));
    }

    /**
     * 一般存储供方查询关键岗位
     *
     * @param supplierId
     * @return
     */
    public List<SupplierStaff> listCommonStorageSupplierStaff(Long supplierId) {
        KeyPost[] keyPosts = new KeyPost[]{KeyPost.KEY_POST_TYPE_TWO, KeyPost.KEY_POST_TYPE_ONE};
        return supplierStaffDao.listSupplierStaff(supplierId, keyPosts);
    }

}
